﻿using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
using System.Collections.Generic;

public enum MoreGameAnimationType
{
	MGAT_NORMAL = 0,
	MGAT_BOUNCE,
	MGAT_EXPAND
};


public class MoreGameManagerScript {

	/* Interface to native implementation */
	#if UNITY_IOS
	[DllImport ("__Internal")]
	private static extern void _setGameObjectNameForMGM(string gameObjectName);

	[DllImport ("__Internal")]
	private static extern string _getIconsPath();

	[DllImport ("__Internal")]
	private static extern string _getButtonImagePath();

	[DllImport ("__Internal")]
	private static extern string _getDefaultAppIconPath();

	[DllImport ("__Internal")]
	private static extern string _getFirstAppIconPath();

	[DllImport ("__Internal")]
	private static extern string _getSmallButtonImagePath();

	[DllImport ("__Internal")]
	private static extern void _refresh();

	[DllImport ("__Internal")]
	private static extern void _show(int animation = (int)MoreGameAnimationType.MGAT_EXPAND);
	#endif


	public void setGameObjectNameForMGM(string gameObjectName) 
	{
		// Call plugin only when running on real device
		if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) {
			#if UNITY_ANDROID
			SSCMoreGamesAdapter.getInstance().setGameObjectName(gameObjectName);
			#elif UNITY_IOS
			_setGameObjectNameForMGM(gameObjectName);
			#endif
		}
	}

	public List<string> getIconsPath()
	{
		// Call plugin only when running on real device
		if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) {
			#if UNITY_ANDROID
			return SSCMoreGamesAdapter.getInstance().getIconsPath();
			#elif UNITY_IOS
			string paths = _getIconsPath ();
			string[] strarr = paths.Split(',');
			List<string> list = new List<string>();
			foreach(string str in strarr)
			{
				Debug.Log("====="+str);
				if(str.Length > 0)
					list.Add(str);
			}

			return list;
			#endif
		}

		return null;
	}

	public string getButtonImagePath() 
	{
		// Call plugin only when running on real device
		if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) {
			#if UNITY_ANDROID
			return SSCMoreGamesAdapter.getInstance().getButtonImagePath();
			#elif UNITY_IOS
			return _getButtonImagePath ();
			#endif
		}

		return "";
	}

	public string getDefaultAppIconPath() 
	{
		// Call plugin only when running on real device
		if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) {
			#if UNITY_ANDROID
			return SSCMoreGamesAdapter.getInstance().getDefaultAppIconPath();
			#elif UNITY_IOS
			return _getDefaultAppIconPath ();
			#endif
		}

		return "";
	}

	public string getFirstAppIconPath() 
	{
		// Call plugin only when running on real device
		if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) {
			#if UNITY_ANDROID
			return SSCMoreGamesAdapter.getInstance().getFirstAppIconPath();
			#elif UNITY_IOS
			return _getFirstAppIconPath ();
			#endif
		}

		return "";
	}

	public string getSmallButtonImagePath() 
	{
		// Call plugin only when running on real device
		if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) {
			#if UNITY_ANDROID
			return SSCMoreGamesAdapter.getInstance().getSmallButtonImagePath();
			#elif UNITY_IOS
			return _getSmallButtonImagePath ();
			#endif
		}

		return "";
	}

	public void refresh() 
	{
		// Call plugin only when running on real device
		if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) {
			#if UNITY_ANDROID
			 SSCMoreGamesAdapter.getInstance().refresh();
			#elif UNITY_IOS
			_refresh ();
			#endif
		}
	}

	public void show(int animation = (int)MoreGameAnimationType.MGAT_EXPAND) 
	{
		// Call plugin only when running on real device
		if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.Android) {
			#if UNITY_ANDROID
			SSCMoreGamesAdapter.getInstance().show(animation);
			#elif UNITY_IOS
			_show (animation);
			#endif
		}
	}

}
